<?php

namespace App\Services;

    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */

/**
 * Description of Permission
 *
 * @author dung
 */
use Config,
    File,
    Log,
    Sentry;

class Permission
{

    public function is_admin()
    {
        // check if user is logged in
        if (!Sentry::check()) {
            return false;
        }
        // check if user has access to the admin page
        if (!Sentry::getUser()->hasAccess('admin')) {
            return false;
        }
        return true;
    }

    public function has_access($module, $action, $userId = 0)
    {
        if (!Sentry::check()) {
            return false;
        }
        if (Sentry::getUser()->hasAnyAccess([$module, $module . '.full'])) {
            return true;
        }
        if ($userId && Sentry::getId() != $userId) {
            return false;
        }
        if (!Sentry::getUser()->hasAnyAccess([$module, $module . '.' . $action])) {
            return false;
        }
        return true;
    }

}
